//
//  CJIdentityAuthenticationController.m
//  Boss
//
//  Created by admin on 2018/9/13.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJIdentityAuthenticationController.h"
#import "WYUploadModel.h"
#import "UIImage+WYSaveImage.h"
#import "BXTextField.h"
#import "CJUploadAuthenticationSucessController.h"

@interface CJIdentityAuthenticationController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIView *mainView;

@property (nonatomic,strong)NSString *pathString;

@property (nonatomic,strong)WYUploadModel *model;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topHeight;

@property (strong, nonatomic) IBOutlet UIImageView *positiveImageView;

@property (strong, nonatomic) IBOutlet UIImageView *negativeImageView;

@property (nonatomic,strong) NSString *positiveString;
@property (nonatomic,strong) NSString *negativeString;

@property (nonatomic)BOOL type;
@property (strong, nonatomic) IBOutlet UITextField *nameTextField;

@property (strong, nonatomic) IBOutlet BXTextField *idTextField;
@property (strong, nonatomic) IBOutlet UIButton *upLoadBtn;

@end

@implementation CJIdentityAuthenticationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.topHeight.constant = self.navHeight;
}

-(void)setupUI
{
    self.mainView.width = kScreenWidth;
    self.mainView.height = kScreenHeight;
    
    [self.scrollView addSubview:self.mainView];
    self.scrollView.contentSize = self.mainView.size;
    
    self.navigationItem.title = @"身份认证";
    
    self.upLoadBtn.userInteractionEnabled = NO;
    
    
    [self.nameTextField addTarget:self action:@selector(numberTextFieldChanged:) forControlEvents:UIControlEventEditingChanged];
    [self.idTextField addTarget:self action:@selector(numberTextFieldChanged:) forControlEvents:UIControlEventEditingChanged];
    
    
    
    
}
-(void)numberTextFieldChanged:(UITextField *)textField
{
    if (textField == self.idTextField) {
        if (self.idTextField.text.length>18) {
            self.idTextField.text = [self.idTextField.text substringToIndex:18];
        }
    }
    if (self.idTextField.text.length&&self.nameTextField.text.length) {
        self.upLoadBtn.userInteractionEnabled = YES;
        [self.upLoadBtn setBackgroundColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]];
        
    }else{
        self.upLoadBtn.userInteractionEnabled = NO;
        [self.upLoadBtn setBackgroundColor:[UIColor hexStringToColor:@"#DD8C79" alpha:1.0]];
    }
    
    
}


- (IBAction)upLoadAction:(id)sender {
    
    WEAKSELF
    [WYHttpServer sendPersonAuthenticationMessageWithUserName:self.nameTextField.text WithIDNumber:self.idTextField.text SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            
            CJUploadAuthenticationSucessController *uasc = [[CJUploadAuthenticationSucessController alloc]init];
            [self.navigationController pushViewController:uasc animated:YES];
            
            
          //  weakSelf.navigationController popViewControllerAnimated:<#(BOOL)#>
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
        
        
        
    }];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end
